<?php include "conn.php";?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品列表-<?php echo $SiteTitle;?></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> -->
    <meta name="keywords" content="商品列表-<?php echo $SiteKeywords;?>  ">
    <meta name="description" content="商品列表-<?php echo $SiteDescription;?> " />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />    <!-- <link rel="stylesheet" href="http://at.alicdn.com/t/font_1468307_iqx9x2fm78n.css"> -->
    <?php include "public/cssjs.php";?>
    <link rel="stylesheet" type="text/css" href="css/product.css" />
</head>
<body>
<?php include "public/top.php";?>

<section id="swiper1" class="swiper">
    <div class="swiper-container ">
        <div class="swiper-wrapper">
            <?php
            $connt = new Mysql();
            $rs = $connt->getRow("select * from lunbo");
            if($rs["a1_img"]!=""){ echo '<div class="swiper-slide"><img src="pic/'.$rs["a1_img"].'" alt="" class="img-fluid"></div>';}
            if($rs["a2_img"]!=""){ echo '<div class="swiper-slide"><img src="pic/'.$rs["a2_img"].'" alt="" class="img-fluid"></div>';}
            if($rs["a3_img"]!=""){ echo '<div class="swiper-slide"><img src="pic/'.$rs["a3_img"].'" alt="" class="img-fluid"></div>';}
            if($rs["a4_img"]!=""){ echo '<div class="swiper-slide"><img src="pic/'.$rs["a4_img"].'" alt="" class="img-fluid"></div>';}
            if($rs["a5_img"]!=""){ echo '<div class="swiper-slide"><img src="pic/'.$rs["a5_img"].'" alt="" class="img-fluid"></div>';}
            ?>
        </div>
        <!-- 如果需要分页器 -->
        <div class="swiper-pagination"></div>
        <!-- 如果需要滚动条 -->
    </div>
</section>
<!--  -->
<?php
if(isset($_GET["orderby"])){
    $orderby=$_GET["orderby"];
}else{
    $orderby="adate";
}
if(isset($_GET["type"])){$there="type=".$_GET["type"];
$conn=new Mysql();
    $rs=$conn->getRow("select title from newscata_product where id=".$_GET["type"]);
    $alltitle=$rs["title"];
}else{$there=" 1=1";
    $alltitle="全部商品";
}
$conn=new Mysql();
$sql = "select * from products where $there order by ".$orderby." desc";
$page_size = 8;					 //定义每页显示多少记录
$num_cnt = mysqli_num_rows($conn->query($sql)); //获取总记录数
$page_cnt = ceil($num_cnt/$page_size);  //计算总页数
if(isset($_GET["page"])){
    $page = intval($_GET["page"]);
}else{
    $page = 1;
}
if ($page<1)
{
    $page=1;
}
elseif ($page>$page_cnt)
{
    $page=$page_cnt;
}
$query_start = ($page - 1 ) * $page_size;   //计算每页开始的记录号
$query_sql = $sql." limit $query_start,$page_size"; //使用limit获取记录
?>
<!--  -->
<div class="home-m home-productList">
    <div class="container">
        <div class="home-heading">
            <div class="home-operation">
                <div class="row active" onclick="listType(this, 'row')">
                    <img src="images/tab_icon1_0.png" alt="">
                    <img src="images/tab_icon1_1.png" alt="">
                </div>
                <div class="row" onclick="listType(this, 'column')">
                    <img src="images/tab_icon2_0.png" alt="">
                    <img src="images/tab_icon2_1.png" alt="">
                </div>
            </div>
            <div class="home-title"><span><?php echo $alltitle;?></span></div>
        </div>
        <div class="tab row">
            <div class="col-md-3 mb-4">
                <div class="dropdown show">
                    <span>
                        排队：
                    </span>
                    <a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        最新
                    </a>

                    <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
                        <a class="dropdown-item" href="?orderby=adate">最新</a>
                        <a class="dropdown-item" href="?orderby=LinkCount">最多关注</a>
                    </div>
                </div>
            </div>
            <div class="col-md-9 mb-4">
                <div class="page text-center text-md-right">
                    <nav aria-label="Page navigation example">
                        <?php Pagefenye($num_cnt,$page_cnt,$page);?>
                    </nav>
                </div>
            </div>
        </div>
        <div class="home-body home-body-column">
            <div class="row">
                <?php

                if($num_cnt>0) {
                    $i = 1;
                    $row = $conn->getAll($query_sql);
                    foreach ($row as $key => $rsp) {
                        ?>
                        <div class="col-md-6 col-xl-3 mb-4">
                            <div class="home-someProducts-item">
                                <div class="label"><?php echo $rsp["objects"];?></div>
                                <div class="home-someProducts-img"><a href="detail.php?id=<?php echo $rsp["id"];?>"><img class="hvr-grow" src="/pic/<?php echo $rsp["pic"];?>" alt="<?php echo $rsp["title"];?>"></a>
                                    <div class="home-someProducts-action"><a href="shoppingCart.php">加入购物车 <i class="iconfont icon-gouwuche"></i></a></div>
                                </div>
                                <div class="home-someProducts-caption">
                                    <div class="home-someProducts-title"><?php echo $rsp["title"];?></div>
                                    <div class="home-someProducts-rating"><?php echo $rsp["styles"];?></div>
                                    <div class="home-someProducts-price"><small>¥<?php echo $rsp["ys_s_price"];?></small>¥<?php echo $rsp["ys_e_price"];?></div>
                                    <div class="home-someProducts-info"><?php echo $rsp["title_f"];?></div>
                                    <div class="home-someProducts-collection active">
                                        <p class="join"><i class="iconfont icon-collection"></i>加入收藏</p>
                                        <p class="ing"><i class="iconfont icon-collection"></i>已在收藏</p>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <?php
                    }
                }else{
                    echo "<p style='text-align: center'>暂无产品信息</p>";

                }
                ?>


            </div>
        </div>

        <div class="page">
            <nav aria-label="Page navigation example">
                <?php Pagefenye($num_cnt,$page_cnt,$page);?>
            </nav>
        </div>
    </div>
</div>


<!--  -->
<?php include "public/footer.php";?>
<?php include "public/bottom.php";?>
<script>
    function listType (even, val) {
        $(even).addClass('active').siblings().removeClass('active');
        if ( val === 'column') {
            $('.home-body').removeClass('home-body-column');
            $('.home-body .row>div').addClass('col-xl-12');
            $('.home-body .row>div').addClass('col-md-12');
            $('.home-body .row>div').addClass('mb-12');
        } else {
            $('.home-body').addClass('home-body-column');
            $('.home-body .row>div').removeClass('col-xl-12');
            $('.home-body .row>div').removeClass('col-md-12');
            $('.home-body .row>div').removeClass('mb-12');
        }
        // if ()
    };
    $(function () {
        $('.home-someProducts-collection').on('click', function () {
            if ($('.home-someProducts-collection').hasClass('active')){
                $(this).removeClass('active')
            } else {
                $(this).addClass('active')
            }
        })
    })
</script>
</body>

</html>